﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using BLL;

public partial class QuarterPlan_QuarterAttachmentPath : System.Web.UI.Page
{
    string path = HttpContext.Current.Server.MapPath("~/") + @"Upload\";
    QuarterPlanofManager dllQuarterPlanofManager = new QuarterPlanofManager();
    MonthPlanManager dllMonthPlanManager = new MonthPlanManager();
    WeekPlanofManager dllWeekPlanofManager = new WeekPlanofManager();
    UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
    UserPlanWeek dllUserPlanWeek = new UserPlanWeek();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /// <summary>
    /// 提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        int _planType = Utility.HttpHelp.getParamsInt("PlanType");
        if (this.fupAttachmentPath.FileName.Length > 0)
        {
            //获得附件文件名
            string _filename = this.fupAttachmentPath.FileName;
            if (_planType == 18)
            {
                path = HttpContext.Current.Server.MapPath("~/") + @"Upload\FishBoneDiagram\";
            }
            if (_planType == 19)
            {
                path = HttpContext.Current.Server.MapPath("~/") + @"Upload\YearIntroduction\";
            }
            //判断是否存在
            if (System.IO.File.Exists(path + _filename))
            {//如果存在就删除已存在
                System.IO.File.Delete(path + _filename);
            }

            this.fupAttachmentPath.SaveAs(path + _filename);
            //构造数组
            object[] _planRecord = new object[2];
            //页面传年计划ID

            int result = 0;
            _planRecord[1] = path + _filename;//
            if (_planType == 1)//年计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllQuarterPlanofManager.edit(QuarterPlanofManager.field.QuarterPlanId.ToString(), _planRecord);
            }
            if (_planType == 2 || _planType == 4)//月计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllMonthPlanManager.edit(MonthPlanManager.field.MonthPlanId.ToString(), _planRecord);
            }
            if (_planType == 3 || _planType == 5)//周计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllWeekPlanofManager.edit(WeekPlanofManager.field.WeekPlanId.ToString(), _planRecord);
            }
            if (_planType == 6)//员工月计划添加类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllUserPlanMonth.edit(UserPlanMonth.field.MonthPlanId.ToString(), _planRecord);
            }
            if (_planType == 7)//员工周计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllUserPlanWeek.edit(UserPlanWeek.field.WeekPlanId.ToString(), _planRecord);
            }
            if (_planType == 8)//员工月计划草稿类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllUserPlanMonth.edit(UserPlanMonth.field.MonthPlanId.ToString(), _planRecord);
            }
            if (_planType == 9)//员工周计划草稿类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = dllUserPlanWeek.edit(UserPlanWeek.field.WeekPlanId.ToString(), _planRecord);
            }
            if (_planType == 10)//总表计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                TotalPlanMgr dllTotalPlanMgr = new TotalPlanMgr();
                result = dllTotalPlanMgr.editAttachmentPath(_planRecord);
            }
            if (_planType == 11)//总表计划类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                TotalPlanMgr dllTotalPlanMgr = new TotalPlanMgr();
                result = dllTotalPlanMgr.editAttachmentPath(_planRecord);
            }
            if (_planType == 12)//上年总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.QuarterSummary().editPreAttachmentPath(_planRecord);
            }
            if (_planType == 13)//上月总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.MonthSummary().editPreAttachmentPath(_planRecord);
            }
            if (_planType == 14)//上周总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.WeekSummary().editPreAttachmentPath(_planRecord);
            }
            if (_planType == 15)//本年总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.QuarterSummary().editAttachmentPath(_planRecord);
            }
            if (_planType == 16)//本月总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.MonthSummary().editAttachmentPath(_planRecord);
            }
            if (_planType == 17)//本周总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.WeekSummary().editAttachmentPath(_planRecord);
            }
            if (_planType == 18)//鱼骨图类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.FishBoneDiagram().UploadAttachmentPath(_planRecord);
            }
            if (_planType == 19)//前言类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.YearIntroduction().UploadAttachmentPath(_planRecord);
            }
            if (_planType == 20)//专项计划
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.SpecialPlan().UploadAttachmentPath(_planRecord);
            }
            if (_planType == 21)//员工本月总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.UserMonthSummary().editAttachmentPath(_planRecord);
            }
            if (_planType == 22)//员工上月总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.UserMonthSummary().editPreAttachmentPath(_planRecord);
            }
            if (_planType == 23)//员工本周总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.UserWeekSummary().editAttachmentPath(_planRecord);
            }
            if (_planType == 24)//员工上周总结类型
            {
                _planRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");
                result = new BLL.UserWeekSummary().editPreAttachmentPath(_planRecord);
            }
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("上传文件未成功，请重试！");
            }
            else
            {
                if (_planType == 1)
                {
                    Page.RegisterStartupScript("alert",
                  "<script language=javascript>window.opener.location='../QuarterPlan/DraftQuarterPlan.aspx';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 2)
                { 
                    Page.RegisterStartupScript("alert",
                 "<script language=javascript>window.opener.location='../Month/DraftMonthPlan.aspx';alert('上传成功！');window.close();</script>");  
                }

                if (_planType == 3)
                {
                    //Utility.HttpHelp.closeWindow("../Week/DraftWeekPlan.aspx", Page);
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../Week/DraftWeekPlan.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 4)
                {
                    Page.RegisterStartupScript("alert",
                 "<script language=javascript>window.opener.location='../Month/MonthPlanAdd.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 5)
                {
                    //Utility.HttpHelp.closeWindow("../Week/WeekPlanAdd.aspx", Page);
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../Week/WeekPlanAdd.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 6)
                {
                    //Utility.HttpHelp.closeWindow("../UserPlanMonth/UserPlanMonthAdd.aspx", Page);
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../UserPlanMonth/UserPlanMonthAdd.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 7)
                { 
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../Week/WeekPlanAdd.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 8)
                { 
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../UserPlanMonth/UserPlanDraftMonth.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 9)
                {
                    //Utility.HttpHelp.closeWindow("../UserPlanWeek/DraftUserWeekPlan.aspx", Page);
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../UserPlanWeek/DraftUserWeekPlan.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 10)
                {
                    string department = Server.UrlDecode(Utility.HttpHelp.getParamsString("department"));
                    string Year = Utility.HttpHelp.getParamsString("Year");
                    
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../TotalPlan/DraftTotalPlan.aspx?department=" + department + "&Year=" + Year+"';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 11)
                {
                    string department = Server.UrlDecode(Utility.HttpHelp.getParamsString("department"));
                    string Year = Utility.HttpHelp.getParamsString("Year");
                    
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../TotalPlan/SendTotalPlan.aspx?department=" + department + "&Year=" + Year+"';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 12 || _planType == 15)
                { 
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../QuarterPlan/QuarterPlanList.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 13 || _planType == 16)
                { 
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../Month/MonthPlanList.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 14 || _planType == 17)
                {
                    //Utility.HttpHelp.closeWindow("../Week/WeekPlanList.aspx", Page);
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../Week/WeekPlanList.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 18)
                {
                    //Utility.HttpHelp.closeWindow("../QuarterPlan/AddFishBoneDiagram.aspx?Department=" + Utility.HttpHelp.getParamsString("Department"), Page);
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../QuarterPlan/AddFishBoneDiagram.aspx';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 19)
                { 
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../QuarterPlan/AddYearIntroduction.aspx?Department=" + Utility.HttpHelp.getParamsString("Department")+"';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 20)
                {
                    string url = Utility.HttpHelp.getParamsString("url");                    
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../SpecialPlan/" + url + "?Department=" + Utility.HttpHelp.getParamsString("Department") + "';alert('上传成功！');window.close();</script>");  
                }
                if (_planType == 21)
                {
                    string url = Utility.HttpHelp.getParamsString("url");
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../UserPlanMonth/" + url + "?Department=" + Utility.HttpHelp.getParamsString("Department") + "';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 22)
                {
                    string url = Utility.HttpHelp.getParamsString("url");
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../UserPlanMonth/" + url + "?Department=" + Utility.HttpHelp.getParamsString("Department") + "';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 23)
                {
                    string url = Utility.HttpHelp.getParamsString("url");
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../UserPlanWeek/" + url + "?Department=" + Utility.HttpHelp.getParamsString("Department") + "';alert('上传成功！');window.close();</script>");
                }
                if (_planType == 24)
                {
                    string url = Utility.HttpHelp.getParamsString("url");
                    Page.RegisterStartupScript("alert",
                "<script language=javascript>window.opener.location='../UserPlanWeek/" + url + "?Department=" + Utility.HttpHelp.getParamsString("Department") + "';alert('上传成功！');window.close();</script>");
                }

            }
        }
        else
        {
            //构造数组
            object[] _quaterRecord = new object[2];
            _quaterRecord[1] = "";
            _quaterRecord[0] = Utility.HttpHelp.getParamsInt("PlanId");

            int result = dllQuarterPlanofManager.edit(QuarterPlanofManager.field.QuarterPlanId.ToString(), _quaterRecord);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("上传文件未成功，请重试！");
            }
            else
            {
                if (_planType == 1)
                {
                    Utility.HttpHelp.closeWindow("../QuarterPlan/DraftQuarterPlan.aspx", Page);
                }
                if (_planType == 2)
                {
                    Utility.HttpHelp.closeWindow("../Month/DraftMonthPlan.aspx", Page);
                }

                if (_planType == 3)
                {
                    Utility.HttpHelp.closeWindow("../Week/DraftWeekPlan.aspx", Page);
                }
                if (_planType == 4)
                {
                    Utility.HttpHelp.closeWindow("../Month/MonthPlanAdd.aspx", Page);
                }
                if (_planType == 5)
                {
                    Utility.HttpHelp.closeWindow("../Week/WeekPlanAdd.aspx", Page);
                }
                if (_planType == 6)
                {
                    Utility.HttpHelp.closeWindow("../UserPlanMonth/UserPlanMonthAdd.aspx", Page);
                }
                if (_planType == 7)
                {
                    Utility.HttpHelp.closeWindow("../Week/WeekPlanAdd.aspx", Page);
                }
                if (_planType == 8)
                {
                    Utility.HttpHelp.closeWindow("../UserPlanMonth/UserPlanDraftMonth.aspx", Page);
                }
                if (_planType == 9)
                {
                    Utility.HttpHelp.closeWindow("../UserPlanWeek/DraftUserWeekPlan.aspx", Page);
                }
                if (_planType == 12 || _planType == 15)
                {
                    Utility.HttpHelp.closeWindow("../QuarterPlan/MonthPlanList.aspx", Page);
                }
                if (_planType == 13 || _planType == 16)
                {
                    Utility.HttpHelp.closeWindow("../Month/MonthPlanList.aspx", Page);
                }
                if (_planType == 14 || _planType == 17)
                {
                    Utility.HttpHelp.closeWindow("../Week/DraftUserWeekPlan.aspx", Page);
                }
            }
        }
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("AttachmentPath.aspx");
    }
}
